import requests
class SendMethod:
    @staticmethod
    def send_method(method,url,heders=None,params=None,data=None):
        if method == 'get':
            response = requests.get(url=url, params=params)
        elif method == 'post':
            response = requests.post(url=url, data=data)
        else:
            response = None
            print('请求的方式错误')
        result = {}

        if response is not None:
            result['status_code'] = response.status_code
            result['headers'] = response.headers
            result['boby'] = response.json()
            result["response_time"] = int(response.elapsed.microseconds / 1000)
            return result
        else:
            return response


if __name__ == '__main__':
    url = 'http://127.0.0.1:8000/api/add_event/'
    payload = {'eid': 12,
        'name': 'requests发布会',
        'limit': 3,
        'status': 1,
        'address': 'A4教室',
        'start_time': '2021-10-30 12:00:00'
    }
    method = 'post'

    SendMethod.send_method(method=method, url=url, data=payload)


